package com.zcmyth;

import static org.junit.Assert.*;

import org.junit.Test;

import com.google.common.collect.ImmutableList;

public class BinarySearchTest {

  @Test
  public void empty() {
    int index = BinarySearch.binarySearch(ImmutableList.<Integer> of(), 1);
    assertEquals(-1, index);
  }
  
  @Test
  public void notExist() {
    int index = BinarySearch.binarySearch(ImmutableList.<Integer> of(2,3,4), 1);
    assertEquals(-1, index);
  }
  
  @Test
  public void unique() {
    int index = BinarySearch.binarySearch(ImmutableList.<Integer> of(1,2,3,4,5), 3);
    assertEquals(2, index);
  }
  
  @Test
  public void duplicated() {
    int index = BinarySearch.binarySearch(ImmutableList.<Integer> of(1,1,1), 1);
    assertEquals(0, index);
    
    index = BinarySearch.binarySearch(ImmutableList.<Integer> of(1,1,1,3,3,3), 3);
    assertEquals(3, index);
  }
}
